package com.qing.design.patterns.facade.example.facade;

import com.qing.design.patterns.facade.example.some_complex_media_library.AudioMixer;
import com.qing.design.patterns.facade.example.some_complex_media_library.BitrateReader;
import com.qing.design.patterns.facade.example.some_complex_media_library.Codec;
import com.qing.design.patterns.facade.example.some_complex_media_library.CodecFactory;
import com.qing.design.patterns.facade.example.some_complex_media_library.MPEG4CompressionCodec;
import com.qing.design.patterns.facade.example.some_complex_media_library.OggCompressionCodec;
import com.qing.design.patterns.facade.example.some_complex_media_library.VideoFile;

import java.io.File;

/**
 * 外观提供了进行视频转换的简单接口
 */
public class VideoConversionFacade {

	public File convertVideo(String fileName, String format){
		System.out.println("视频转换：转换已开始。");
		VideoFile file=new VideoFile(fileName);
		Codec sourceCodec= CodecFactory.extract(file);
		Codec destinationCodec;
		if(format.equals("map4")){
			destinationCodec=new OggCompressionCodec();
		}else{
			destinationCodec=new MPEG4CompressionCodec();
		}
		VideoFile buffer= BitrateReader.read(file,sourceCodec);
		VideoFile intermediateResult=BitrateReader.convert(buffer,destinationCodec);

		File result=new AudioMixer().fix(intermediateResult);
		System.out.println("视频转换面：转换完成。");
		return result;
	}

}
